package cn.kailangtu.myapplication.specialview;

import android.widget.ImageView;

import cn.kailangtu.myapplication.R;

public class ElectricView implements BaseSpecialView {
    private boolean isInit = false;
    private ImageView ivLess12000;
    private ImageView ivLess6000;
    private ImageView ivLess0;
    private ImageView iv0;
    private ImageView ivThan0;
    private ImageView ivThan6000;
    private ImageView ivThan12000;
    private ImageView ivThan18000;
    private ImageView ivThan24000;
    private ImageView ivThan30000;
    private ImageView ivThan36000;
    private ImageView ivThan42000;


    private static ElectricView instance;
    public static ElectricView getInstance()
    {
        if(instance == null)
        {
            instance = new ElectricView();
        }
        return instance;
    }


    public void init(ImageView ivTop1,ImageView ivTop2,ImageView ivTop3,ImageView ivTop4,ImageView ivTop5,ImageView ivTop6,ImageView ivTop7,ImageView ivTop8,ImageView ivTop9,ImageView ivTop10,ImageView ivTop11,ImageView ivTop12){
        ivThan42000 = ivTop1;
        ivThan36000 = ivTop2;
        ivThan30000 = ivTop3;
        ivThan24000 = ivTop4;
        ivThan18000 = ivTop5;
        ivThan12000 = ivTop6;
        ivThan6000 = ivTop7;
        ivThan0 = ivTop8;
        iv0 = ivTop9;
        ivLess0 = ivTop10;
        ivLess6000 = ivTop11;
        ivLess12000 = ivTop12;
        isInit = true;
    }

    public ImageView getIvLess12000() {
        return ivLess12000;
    }

    public void setIvLess12000(ImageView ivLess12000) {
        this.ivLess12000 = ivLess12000;
    }

    public ImageView getIvLess6000() {
        return ivLess6000;
    }

    public void setIvLess6000(ImageView ivLess6000) {
        this.ivLess6000 = ivLess6000;
    }

    public ImageView getIvLess0() {
        return ivLess0;
    }

    public void setIvLess0(ImageView ivLess0) {
        this.ivLess0 = ivLess0;
    }

    public ImageView getIv0() {
        return iv0;
    }

    public void setIv0(ImageView iv0) {
        this.iv0 = iv0;
    }

    public ImageView getIvThan0() {
        return ivThan0;
    }

    public void setIvThan0(ImageView ivThan0) {
        this.ivThan0 = ivThan0;
    }

    public ImageView getIvThan6000() {
        return ivThan6000;
    }

    public void setIvThan6000(ImageView ivThan6000) {
        this.ivThan6000 = ivThan6000;
    }

    public ImageView getIvThan12000() {
        return ivThan12000;
    }

    public void setIvThan12000(ImageView ivThan12000) {
        this.ivThan12000 = ivThan12000;
    }

    public ImageView getIvThan18000() {
        return ivThan18000;
    }

    public void setIvThan18000(ImageView ivThan18000) {
        this.ivThan18000 = ivThan18000;
    }

    public ImageView getIvThan24000() {
        return ivThan24000;
    }

    public void setIvThan24000(ImageView ivThan24000) {
        this.ivThan24000 = ivThan24000;
    }

    public ImageView getIvThan30000() {
        return ivThan30000;
    }

    public void setIvThan30000(ImageView ivThan30000) {
        this.ivThan30000 = ivThan30000;
    }

    public ImageView getIvThan36000() {
        return ivThan36000;
    }

    public void setIvThan36000(ImageView ivThan36000) {
        this.ivThan36000 = ivThan36000;
    }

    public ImageView getIvThan42000() {
        return ivThan42000;
    }

    public void setIvThan42000(ImageView ivThan42000) {
        this.ivThan42000 = ivThan42000;
    }

    public void setElectricValue(int newValue)
    {
        if(isInit) {
            resetImage(ivThan42000, 400, newValue);
            resetImage(ivThan36000,350,newValue);
            resetImage(ivThan30000,300,newValue);
            resetImage(ivThan24000,250,newValue);
            resetImage(ivThan18000,200,newValue);
            resetImage(ivThan12000,150,newValue);
            resetImage(ivThan6000,100,newValue);
            resetImage(ivThan0,1,newValue);
            resetImage(ivLess0,-1,newValue);
            resetImage(ivLess6000,-20,newValue);
            resetImage(ivLess12000,-40,newValue);
        }
    }

    private void resetImage(ImageView view ,int thresholdValue,int newValue)
    {
        if(thresholdValue > 0)
        {
            if(newValue >= thresholdValue)
            {
                view.setImageResource(R.drawable.main_eletric_on);
            }
            else
            {
                view.setImageResource(R.drawable.main_eletric_off);
            }
        }
        else if(thresholdValue < 0){
            if(newValue <= thresholdValue)
            {
                view.setImageResource(R.drawable.main_eletric_on);
            }
            else
            {
                view.setImageResource(R.drawable.main_eletric_off);
            }
        }
    }

    @Override
    public void setNewValue(int newValue) {
       // Log.d("SHOOTLEE_NEWVALUE",""+newValue);
        setElectricValue(newValue);
    }

    @Override
    public int getPage() {
        return R.id.llPage0;
    }

    @Override
    public String getCanID() {
        return "CAN043D9CF4H34J0.1P_16000";
    }
}
